<?php
class Clound_Datetime extends Zend_Date 
{
	public static $_instance = null;
    public function __construct($date = null, $part = null, $locale = null)
    {
		parent::__construct($date, $part, $locale);
	}
	/**
     * Returns an instance of Clound_Datetime
     *
     * Singleton pattern implementation
     *
     * @return Clound_Datetime Provides a fluent interface
     */
    public static function getInstance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }
	/**
	*
	*	Convert date thành dạng yyyy-MM-dd
	* 	Sử dụng: 	$objDate = new Clound_Datetime('20/07/2014', 'dd/MM/yyyy');
	*				$sSendDate = $objDate->ToYYyymmdd();
	*/
	public function ToYYyymmdd() {
		return $this->toString('yyyy-MM-dd');
	}
	/**
	*
	*	Convert date thành dạng dd/MM/yyyy
	* 	Sử dụng: 	$objDate = new Clound_Datetime();
	*				$sSendDate = $objDate->ToYYyymmdd();
	*/
	public function ToDdMMyyyy() {
		return $this->toString('dd/MM/yyyy');
	}
	/**
	*
	*	Lấy năm
	*/
	public function ToYear() {
		return $this->toString('yyyy');
	}
	/**
     * Sets a new date for the date object. Format defines how to parse the date string.
     * Also a complete date with time can be given, but only the date is used for setting.
     * For example: MMMM.yy HH:mm-> May.07 22:11 => 01.May.07 00:00
     * Returned is the new date object and the existing time is left as it was before
     *
     * @param  string  $date    Date to set
     * @param  string                          $format  OPTIONAL Date format for parsing
     * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
     * @return Zend_Date Provides fluid interface
     * @throws Zend_Date_Exception
     */
	public function convertDateTime($date,$format ='dd/M/YY') {
		$sDate = '';
		if ($date) {
			try {
				$this->setDate($date,$format);
				$sDate = $this->toString('yyyy/MM/dd H:m:s');
		        $this->setDate(date('Y/m/d H:i:s'),'Y/MM/D HH:mm-SS');
			} catch (Exception $e) {
				echo $e->getMessage();
			}
		}
        return $sDate;
	}
	
}